import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';

function jiandun_destory(buff: Buff) {
    ShieldSystem.移除指定护盾(buff.getParent(), 'buff_ruin_jiandun', buff.getParent());
}

function biyou_action() {
    EventManager.受到致命伤害((d) => {
        if (!BuffUtil.hasUnitBuff(d.target, 'buff_ruin_biyou')) return;
        d.lastDamage = 0;
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl', d.target, 'overhead'));
        SetUnitLifePercentBJ(d.target, 50);
        SetUnitManaPercentBJ(d.target, 50);
    });
}

function huichun_interval(buff: Buff) {
    let dmg = GetUnitState(buff.getParent(), UNIT_STATE_MAX_LIFE) * 0.09;
    DamageSystemInstance.applyHeal(buff.getParent(), buff.getParent(), dmg);
}
function yiqi_interver(buff: Buff) {
    let dmg = GetUnitState(buff.getParent(), UNIT_STATE_MAX_MANA) * 0.12;
    RegenSystemInstance.regenMana(buff.getParent(), dmg);
}

export const ruinCongi: { [key: string]: AppBuffType } = {
    柳生: {
        id: 'buff_ruin_liusheng',
        name: '柳生神符',
        ubertip: '提供 [|cff00dd2235%|r] |cffffcc00法术暴击|r 与 [|cff00dd22150%|r] |cffffcc00法术暴击伤害|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNStone.blp',
        targetAttach: 'overhead',
        attribute: {
            法术暴击机率: 0.35,
            法术暴击伤害: 1.5,
        },
        targetArt: 'Abilities\\Spells\\Other\\Drain\\DrainCaster.mdl',
        dur: 15,
    },
    鬼兽: {
        id: 'buff_ruin_guishou',
        name: '鬼兽神符',
        ubertip: '提供 [|cff00dd2240%|r] |cffffcc00物理暴击|r 与 [|cff00dd22120%|r] |cffffcc00物理暴击伤害|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNMetamorphosis.blp',
        targetAttach: 'overhead',
        attribute: {
            物理暴击机率: 0.4,
            物理暴击伤害: 1.2,
        },
        targetArt: 'Abilities\\Spells\\Other\\SoulBurn\\SoulBurnbuff.mdl',
        dur: 15,
    },
    回春: {
        id: 'buff_ruin_huichun',
        name: '回春神符',
        ubertip: '每秒恢复 [|cff00dd229%|r] 的 |cffffcc00最大生命|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNHealthStone.blp',
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Items\\ScrollOfRejuvenation\\ScrollManaHealth.mdl',
        dur: 15,
        interval: 1,
        onInterval: huichun_interval,
    },
    益气: {
        id: 'buff_ruin_yiqi',
        name: '益气神符',
        ubertip: '每秒恢复 [|cff00dd2212%|r] 的 |cffffcc00最大魔法|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNManaStone.blp',
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Items\\ClarityPotion\\ClarityTarget.mdl',
        dur: 15,
        interval: 1,
        onInterval: yiqi_interver,
    },
    暴虐: {
        id: 'buff_ruin_baonue',
        name: '暴虐神符',
        ubertip: '提升 [|cff00dd22100%|r] 的 |cffffcc00物理伤害|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNUndeadShrine.blp',
        targetAttach: 'origin',
        attribute: {
            物理伤害倍率: 1,
        },
        targetArt: 'Abilities\\Spells\\Other\\ANsa\\ANsaTarget.mdl',
        dur: 15,
    },
    元神: {
        id: 'buff_ruin_yuanshen',
        name: '元神神符',
        ubertip: '提升 [|cff00dd22100%|r] 的 |cffffcc00魔法伤害|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNRune.blp',
        targetAttach: 'overhead',
        attribute: {
            法术伤害倍率: 1,
        },
        targetArt: 'Abilities\\Spells\\Other\\Drain\\ManaDrainTarget.mdl',
        dur: 15,
    },
    圣水: {
        id: 'buff_ruin_shengshui',
        name: '圣水神符',
        dur: 0.5,
        ubertip: '',
        art: 'ReplaceableTextures\\CommandButtons\\BTNCheese.blp',
    },
    激进: {
        id: 'buff_ruin_jijin',
        name: '激进神符',
        ubertip: '提升 [|cff00dd22300|r] 的 |cffffcc00攻速|r 与 [|cff00dd2235%|r] 的 |cffffcc00法术冷却|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNSpellSteal.blp',
        targetAttach: 'overhead',
        attribute: {
            attackSpd_p: 3,
            冷却_jijin: 0.35,
        },
        targetArt: 'Abilities\\Spells\\Orc\\TrollBerserk\\TrollBeserkerTarget.mdl',
        dur: 15,
    },
    坚韧: {
        id: 'buff_ruin_jianren',
        name: '坚韧神符',
        ubertip: '提升 [|cff00dd22500|r] 的 |cffffcc00护甲|r 与 |cffffcc00魔抗|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNCommand.blp',
        targetAttach: 'overhead',
        attribute: {
            附加护甲: 500,
            附加魔抗: 500,
        },
        targetArt: 'Abilities\\Spells\\Other\\ANrm\\ANrmTarget.mdl',
        dur: 15,
    },
    坚盾: {
        id: 'buff_ruin_jiandun',
        name: '坚盾神符',
        ubertip: '提供相当于 [|cffffcc00最大生命|r] [|cff00dd22100%|r] 的 |cffffcc00生命护盾|r ， 持续 15 秒',
        art: 'ReplaceableTextures\\CommandButtons\\BTNLightningShield.blp',
        targetAttach: 'origin',
        targetArt: '714.mdx',
        dur: 15,
        onDestroy: jiandun_destory,
    },
    庇佑: {
        id: 'buff_ruin_biyou',
        name: '庇佑神符',
        ubertip: '免疫一次死亡，并回复 [|cff00dd2250%|r] 的 |cffffcc00最大生命|r 与 |cffffcc00最大魔法|r',
        art: 'ReplaceableTextures\\CommandButtons\\BTNAnkh.blp',
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Items\\OrbDarkness\\OrbDarkness.mdl',
        dur: 15,
        action: biyou_action,
    },
};

export const idMap: { [key: string]: string } = {
    F000: ruinCongi.柳生.id,
    F001: ruinCongi.鬼兽.id,
    F002: ruinCongi.回春.id,
    F003: ruinCongi.益气.id,
    F004: ruinCongi.暴虐.id,
    F005: ruinCongi.元神.id,
    F006: ruinCongi.圣水.id,
    F007: ruinCongi.激进.id,
    F008: ruinCongi.坚韧.id,
    F009: ruinCongi.坚盾.id,
    F00A: ruinCongi.庇佑.id,
};

export const RuinIds = Object.keys(idMap);

export const idMapRuins: { [key: string]: AppBuffType } = {
    F000: ruinCongi.柳生,
    F001: ruinCongi.鬼兽,
    F002: ruinCongi.回春,
    F003: ruinCongi.益气,
    F004: ruinCongi.暴虐,
    F005: ruinCongi.元神,
    F006: ruinCongi.圣水,
    F007: ruinCongi.激进,
    F008: ruinCongi.坚韧,
    F009: ruinCongi.坚盾,
    F00A: ruinCongi.庇佑,
};
